

require "common.base.luaext"
local UIManager = require("ui.UIManager")
local SceneManager = require("ui.SceneManager")


--服务唯一全局变量, 
global = {}
--禁止出现别的全局变量
function disable_global()
    local __g = _G
    setmetatable(global, {
        __newindex = function(_, name, value)
            rawset(__g, name, value)
        end,
        __index = function(_, name)
            return rawget(__g, name)
        end
    })
    --防止手误写出全局变量
    setmetatable(__g, {
        __newindex = function(_, name, value)
            local msg = "USE 'global.%s = value' INSTEAD OF SET GLOBAL VARIABLE"
            error(string.format(msg, name), 0)
        end,
    })
end
-- disable_global()

local ui_manager = UIManager.new()
local scene_manager = SceneManager.new()


global.ui_manager = ui_manager
global.scene_manager = scene_manager
global.gooi = gooi



function love.load()
    scene_manager:load()
    love.graphics.setBackgroundColor(0.5, 0.5, 0.5, 1)
end

function love.draw()
    scene_manager:draw()
end

function love.update(dt)
    scene_manager:update(dt)
end

function love.mousereleased(x, y, button)
    scene_manager:mousereleased(x, y, button)
end

function love.mousepressed(x, y, button)
    scene_manager:mousepressed(x, y, button)
end

function love.textinput(text)
    print("___________11111111")
    scene_manager:textinput(text)
end

function love.keypressed(key, scancode, isrepeat)
    scene_manager:keypressed(key, scancode, isrepeat)
end

function love.keyreleased(key, scancode)
    scene_manager:keyreleased(key, scancode)
end


--[[
local nuklear = require 'nuklear'

local ui

function love.load()
    ui = nuklear.newUI()
end

local combo = {value = 1, items = {'A', 'B', 'C'}}

function love.update(dt)
    ui:frameBegin()
    if ui:windowBegin('Simple Example', 100, 100, 200, 160,
            'border', 'title', 'movable') then
        ui:layoutRow('dynamic', 30, 1)
        ui:label('Hello, world!')
        ui:layoutRow('dynamic', 30, 2)
        ui:label('Combo box:')
        if ui:combobox(combo, combo.items) then
            print('Combo!', combo.items[combo.value])
        end
        ui:layoutRow('dynamic', 30, 3)
        ui:label('Buttons:')
        if ui:button('Sample') then
            print('Sample!')
        end
        if ui:button('Button') then
            print('Button!')
        end
    end
    ui:windowEnd()
    ui:frameEnd()
end

function love.draw()
    ui:draw()
end

function love.keypressed(key, scancode, isrepeat)
    ui:keypressed(key, scancode, isrepeat)
end

function love.keyreleased(key, scancode)
    ui:keyreleased(key, scancode)
end

function love.mousepressed(x, y, button, istouch, presses)
    ui:mousepressed(x, y, button, istouch, presses)
end

function love.mousereleased(x, y, button, istouch, presses)
    ui:mousereleased(x, y, button, istouch, presses)
end

function love.mousemoved(x, y, dx, dy, istouch)
    ui:mousemoved(x, y, dx, dy, istouch)
end

function love.textinput(text)
    ui:textinput(text)
end

function love.wheelmoved(x, y)
    ui:wheelmoved(x, y)
end

--]]